#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define XH(i,a,b) for(int i = a; i < b; ++i)
#define XXH(i,b,a) for(int i = b; i >= a; --i)
#define Module 998244353
int tmpInt;ll tmpll;string tmpStr;char tmpChar;
vector<int>tmpIntVector;

vector<int>maxHeap;

void adjust(){
  int size = maxHeap.size();
  if(size == 1)return;
  if(maxHeap[size - 1] <= maxHeap[size/2-1])return;
  while(maxHeap[size-1] > maxHeap[size/2 - 1]){
    swap(maxHeap[size-1],maxHeap[size/2-1]);
    size = size/2;
    if(size == 1)break;
  }
}

int main(){
  int n,m;
  cin>>n>>m;
  XH(i,0,n){
    scanf("%d", &tmpInt);
    maxHeap.push_back(tmpInt);
    adjust();
  }
//  XH(i,0,n)cout<<maxHeap[i]<<" ";
  getchar();
  XH(i,0,m){
    getline(cin,tmpStr,'\n');
    stringstream ss(tmpStr);
    if(tmpStr[tmpStr.size()-1] == 't'){
      ss>>tmpInt;
      if(tmpInt == maxHeap[0])printf("1");
      else printf("0");
    }else if(tmpStr[tmpStr.size()-1] == 's'){
      int x,y;
      ss>>x>>tmpChar>>tmpStr>>y;
      int yes = 0;
      XH(j,0,n){
        if(j != n -1 && (maxHeap[j] == x || maxHeap[j] == y)){
          if( ((j+1)/2==(j+2)/2) && maxHeap[j] + maxHeap [j+1] == x + y){
            yes = 1;
            break;
          }   
        }
      }
      if(yes)printf("1");
      else printf("0");
    }else if(tmpStr.find("parent")<tmpStr.size()){
      int x,y;
      ss>>x>>tmpChar>>tmpStr>>tmpStr>>tmpStr>>tmpStr>>y;
      int yes = 0;
      XH(j,0,n){
        if(maxHeap[j] == x && ((j * 2 +1 < n && maxHeap[j*2+1]==y)||(j * 2 +1 < n && maxHeap[j*2+2]==y))){
          yes = 1;
          break;
        }
      }
      if(yes)printf("1");
      else printf("0");
    }else if(tmpStr.find("left")<tmpStr.size()){
      int x,y;
      ss>>x>>tmpChar>>tmpStr>>tmpStr>>tmpStr>>tmpStr>>tmpStr>>y;
      int yes = 0;
      XH(j,0,n){
        if(maxHeap[j] == y && (j * 2 +1 < n && maxHeap[j*2+1]==x)){
          yes = 1;
          break;
        }
      }
      if(yes)printf("1");
      else printf("0");
    }else if(tmpStr.find("right")<tmpStr.size()){
      int x,y;
      ss>>x>>tmpChar>>tmpStr>>tmpStr>>tmpStr>>tmpStr>>tmpStr>>y;
      int yes = 0;
      XH(j,0,n){
        if(maxHeap[j] == y && (j * 2 +1 < n && maxHeap[j*2+2]==x)){
          yes = 1;
          break;
        }
      }
      if(yes)printf("1");
      else printf("0");
    }
  }

  return 0;
}
